﻿using System.Linq;
using System.Windows;
using Creventive.Wpf.ShellFactory.Modules;
using Creventive.Wpf.ShellFactory.Workspace;
using MultiViewWithLogin.Shell.Login;

namespace MultiViewWithLogin.Shell
{
    /// <summary>
    ///   Interaction logic for App.xaml
    /// </summary>
    public partial class App : ShellApplication
    {
        public App()
        {
            this.InitializeComponent();
        }

        private void ShellApplication_Startup(object sender, StartupEventArgs e)
        {
            // This window must be set before login, or the application will shut down. An alternative is to set ShutdownMode to OnExplicitShutdown and handle it yourself.
            this.MainWindow = new MainWindow();

            // Show a login view as a dialog.
            var loginView = new LoginView();
            var result = WindowWorkspace.ShowDialog(loginView);

            if (result == true)
            {
                // Login succeeded. Show the main window.
                this.MainWindow.Show();
            }
            else
            {
                // Login was cancelled. Close the main window to allow the application to exit.
                this.MainWindow.Close();
            }
        }
    }
}